﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

using System.Drawing;
namespace AI.EditMode
{
    class AddPoint : iEditMode
    {
        Point _CurPoint= null;


        //Pen _LinkPen = new Pen(Color.Red, 2f);

        
        Pen _Range_Pen = new Pen(Color.Red, 2f);
                

        public AddPoint(AIInfo Form) :
            base( Form)
        {

            foreach (Point item in _Form._MIM._BaseNode._PointList.Values)
            {
                _Form.listBox1.Items.Add(item);
                
            }

            _Cur_Pen = new Pen(Color.Blue, 2f);

            _Form.PointDelete.Click += new EventHandler(PointDelete_Click);
            _Form.listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
            
        }

        void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            _CurPoint = _Form.listBox1.SelectedItem as Point;
            _Form.propertyGrid1.SelectedObject = _CurPoint;
        }


        void PointDelete_Click(object sender, EventArgs e)
        {
            Point p = _Form.propertyGrid1.SelectedObject as Point;

            if (_Cur_Pen != null)
            {

                _Form._MIM._BaseNode.RemovePoint(p._index);
                _Form.listBox1.Items.Remove(p);
                _Form.propertyGrid1.SelectedObject = null;
                _CurPoint = null;
            }
        }

        public override void MouseClick(MouseButtons button, double x, double y)
        {
            if (button == MouseButtons.Right)
            {
                Point p = _Form._MIM._BaseNode.AddPoint(x, y);
                _Form.listBox1.Items.Add(p);

            }
            else if (button == MouseButtons.Left)
            {
                _CurPoint = _Form._MIM._BaseNode.GetPoint(x, y);
                _Form.propertyGrid1.SelectedObject = _CurPoint;
            }
            
        }

        public override void Draw(Graphics g)
        {
            if (_CurPoint != null)
            {
                //g.DrawEllipse(_Cur_Pen, (float)_CurPoint._P.X-3, (float)_CurPoint._P.Y-3, 6, 6);

                _Form.DrawEllipse(_Cur_Pen, _CurPoint.GPSPos.X, _CurPoint.GPSPos.Y, 6);


                if (_CurPoint.Range == 0)
                {
                    //g.DrawEllipse(_Range_Pen, (float)_CurPoint._P.X-10, (float)_CurPoint._P.Y-10, 20, 20);
                    _Form.DrawEllipse(_Cur_Pen, _CurPoint.GPSPos.X, _CurPoint.GPSPos.Y, 20);
                }
                else
                {
                    _Form.DrawEllipse(_Cur_Pen, _CurPoint.GPSPos.X, _CurPoint.GPSPos.Y, (int)(_CurPoint.Range* 100000));

                    //g.DrawEllipse(_Range_Pen, (float)_CurPoint._P.X - _CurPoint.Range / 2, (float)_CurPoint._P.Y - _CurPoint.Range / 2, _CurPoint.Range, _CurPoint.Range);
                }

                
            }
        }



    }
}
